package clock;

import javax.swing.*;
import java.awt.*;
import java.util.*;

/**
 * This applet uses java.util.Timer with an instance of a
 * java.util.TimerTask subclass to run a digital clock.
 */

public class DigitalClock extends JApplet {
	java.util.Timer fTimer = null;
	// Need panel reference in run ().
	DateFormatPanel fClockPanel = null;
	
	public void init () {
		Container content_pane = getContentPane ();
		
		// Create an instance of DrawingPanel
		fClockPanel = new DateFormatPanel ();
		
		// Add the DrawingPanel to the contentPane.
		content_pane.add (fClockPanel);
	}
	
	/** Applet start() method called by browser. **/
	public void start () {
		// Create a timer.
		fTimer = new java.util.Timer ();
		
		// Start the timer immediately and then repeat calls
		// to run in UpdateTask object every second.
		fTimer.schedule (new UpdateTask (), 0, 1000);
	}
	
	/** Stop clock when web page unloaded. **/
	public void stop () {
		// Stop the clock updates.
		fTimer.cancel ();
	}
	
	
	/** Use the inner class technique to define the
	 * TimerTask subclass to update the clock.
	 **/
	class UpdateTask extends java.util.TimerTask {
		public void run () {
			fClockPanel.repaint ();
		}
	}
}// class ClockTimer1